Skip to content

feat(button): [button] add custom-style attribute #3535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2025
Merged

Conversation

James-9696
Copy link
Collaborator

@James-9696 James-9696 commented Jun 25, 2025

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Added support for a custom style property on the button component, allowing users to apply inline styles directly to buttons in both PC and mobile-first modes.
  • Documentation

    • Updated demo descriptions to include information about the new custom style property and its usage for button customization.
  • Style

    • Enhanced demo buttons with custom width styles and extended label text to demonstrate the new styling capability.

Copy link

coderabbitai bot commented Jun 25, 2025

Walkthrough

A new customStyle (or custom-style) property was introduced to the button component across both PC and mobile-first implementations. This prop enables passing custom inline style objects to the button element. Demo files and documentation were updated to showcase and describe the new styling capability, with example usages reflecting the property.

Changes

File(s) Change Summary
packages/vue/src/button/src/index.ts, .../pc.vue, .../mobile-first.vue Added customStyle prop to button component; binds prop to button's style attribute for custom inline styles.
examples/sites/demos/apis/button.js Added custom-style property to button props array with descriptions and demo references.
examples/sites/demos/pc/app/button/icon.vue, .../icon-composition-api.vue Updated button demo to use :custom-style with maxWidth: 'none' and extended label text.
examples/sites/demos/mobile-first/app/button/type.vue Applied custom-style with maxWidth: 'none' and extended button label text.
examples/sites/demos/pc/app/button/webdoc/button.js, .../mobile-first/app/button/webdoc/button.js Updated demo descriptions to mention new custom-style property for styling buttons.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ButtonComponent
    participant DOM

    User->>ButtonComponent: Passes customStyle prop
    ButtonComponent->>DOM: Renders <button :style="customStyle">
Loading

Poem

In the garden of code, a button anew,
With custom styles, it shines right through.
Stretching wide with maxWidth set,
Demos updated, the best one yet!
Now rabbits can hop with flair and glee,
Styling buttons as fancy as can be!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

examples/sites/demos/pc/app/button/icon-composition-api.vue

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e57bc9 and c54939c.

📒 Files selected for processing (1)
  • examples/sites/demos/pc/app/button/icon-composition-api.vue (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/sites/demos/pc/app/button/icon-composition-api.vue
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the enhancement New feature or request (功能增强) label Jun 25, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
examples/sites/demos/pc/app/button/icon.vue (1)

6-8: Consider a more practical demo example for custom-style.

The current demo uses maxWidth: 'none' with artificially long repeated text, which doesn't showcase a realistic use case. Consider demonstrating more practical styling scenarios like color customization, padding adjustments, or responsive styling.

-        <tiny-button :icon="IconSearch" :custom-style="{ maxWidth: 'none' }">
-          图标按钮图标按钮图标按钮图标按钮
-        </tiny-button>
+        <tiny-button :icon="IconSearch" :custom-style="{ backgroundColor: '#ff6b6b', color: 'white' }">
+          自定义样式按钮
+        </tiny-button>
examples/sites/demos/mobile-first/app/button/type.vue (1)

7-7: Use a more meaningful demo for custom-style feature.

Similar to the PC demo, this example with maxWidth: 'none' and repeated text doesn't demonstrate practical usage of the custom-style feature. Consider showing more realistic styling scenarios.

-    <tiny-button type="warning" :custom-style="{ maxWidth: 'none' }"> 警告按钮 警告按钮警告按钮警告按钮</tiny-button>
+    <tiny-button type="warning" :custom-style="{ borderRadius: '20px', padding: '12px 24px' }"> 自定义圆角警告按钮</tiny-button>
examples/sites/demos/pc/app/button/icon-composition-api.vue (1)

7-8: Consider more practical demo styling.

Similar to other demo files, this example doesn't showcase realistic usage of the custom-style feature.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cce400b and 7e57bc9.

📒 Files selected for processing (9)
  • examples/sites/demos/apis/button.js (1 hunks)
  • examples/sites/demos/mobile-first/app/button/type.vue (1 hunks)
  • examples/sites/demos/mobile-first/app/button/webdoc/button.js (1 hunks)
  • examples/sites/demos/pc/app/button/icon-composition-api.vue (1 hunks)
  • examples/sites/demos/pc/app/button/icon.vue (1 hunks)
  • examples/sites/demos/pc/app/button/webdoc/button.js (1 hunks)
  • packages/vue/src/button/src/index.ts (1 hunks)
  • packages/vue/src/button/src/mobile-first.vue (2 hunks)
  • packages/vue/src/button/src/pc.vue (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*`: 用于写产品需求和开发文档的文件,需求应尽量写得简单清晰易懂。 在需求设计阶段应遵从逐步迭代的原则,早期版本可以尽量简洁。

**/*: 用于写产品需求和开发文档的文件,需求应尽量写得简单清晰易懂。
在需求设计阶段应遵从逐步迭代的原则,早期版本可以尽量简洁。

📄 Source: CodeRabbit Inference Engine (.cursor/rules/product.mdc)

List of files the instruction was applied to:

  • examples/sites/demos/mobile-first/app/button/type.vue
  • packages/vue/src/button/src/pc.vue
  • examples/sites/demos/mobile-first/app/button/webdoc/button.js
  • packages/vue/src/button/src/mobile-first.vue
  • examples/sites/demos/pc/app/button/webdoc/button.js
  • examples/sites/demos/pc/app/button/icon.vue
  • packages/vue/src/button/src/index.ts
  • examples/sites/demos/pc/app/button/icon-composition-api.vue
  • examples/sites/demos/apis/button.js
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (7)
examples/sites/demos/pc/app/button/webdoc/button.js (1)

50-52: Documentation update looks good.

The bilingual documentation correctly describes the new custom-style property and maintains consistency with existing documentation patterns.

packages/vue/src/button/src/pc.vue (2)

33-33: Core implementation is correct.

The style binding correctly applies the customStyle prop to the button element, enabling inline custom styling functionality.


71-71: Prop declaration is properly added.

The customStyle prop is correctly added to the component's props array, completing the feature implementation.

packages/vue/src/button/src/mobile-first.vue (2)

25-25: LGTM! Clean style binding implementation.

The :style="customStyle" binding is correctly placed and follows Vue.js conventions for dynamic style binding.


66-67: LGTM! Prop properly added to component definition.

The customStyle prop is correctly added to the props array following the existing pattern.

examples/sites/demos/mobile-first/app/button/webdoc/button.js (1)

75-77: LGTM! Documentation properly updated for both languages.

The descriptions correctly mention the new custom-style attribute alongside the existing type attribute, maintaining consistency in both Chinese and English versions.

packages/vue/src/button/src/index.ts (1)

82-86: LGTM! Proper prop definition with correct default value pattern.

The customStyle prop is well-defined with:

  • Appropriate Object type for style objects
  • Factory function () => ({}) to prevent reference sharing between component instances
  • Clear JSDoc documentation in Chinese

Comment on lines +66 to +80
{
name: 'custom-style',
type: 'object',
defaultValue: '',
desc: {
'zh-CN': '设置 custom-style 属性按钮样式',
'en-US': 'Set the custom-style attribute to customize the button style'
},
meta: {
stable: '3.25.0'
},
mode: ['pc', 'mobile-first'],
pcDemo: 'icon',
mfDemo: 'type'
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the defaultValue inconsistency.

The API documentation shows defaultValue: '' but the actual implementation in index.ts uses default: () => ({}) which returns an empty object, not an empty string.

Apply this fix to match the implementation:

-          defaultValue: '',
+          defaultValue: '{}',

Otherwise, the API documentation is comprehensive and well-structured with proper bilingual descriptions and version metadata.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
name: 'custom-style',
type: 'object',
defaultValue: '',
desc: {
'zh-CN': '设置 custom-style 属性按钮样式',
'en-US': 'Set the custom-style attribute to customize the button style'
},
meta: {
stable: '3.25.0'
},
mode: ['pc', 'mobile-first'],
pcDemo: 'icon',
mfDemo: 'type'
},
{
name: 'custom-style',
type: 'object',
defaultValue: '{}',
desc: {
'zh-CN': '设置 custom-style 属性按钮样式',
'en-US': 'Set the custom-style attribute to customize the button style'
},
meta: {
stable: '3.25.0'
},
mode: ['pc', 'mobile-first'],
pcDemo: 'icon',
mfDemo: 'type'
},
🤖 Prompt for AI Agents
In examples/sites/demos/apis/button.js around lines 66 to 80, the defaultValue
for the 'custom-style' property is set to an empty string '', but the actual
implementation in index.ts uses a default function returning an empty object.
Update the defaultValue in this file to be a function returning an empty object
to match the implementation and ensure consistency between documentation and
code.

@zzcr zzcr merged commit 4cbe804 into dev Jun 26, 2025
9 of 10 checks passed
@zzcr zzcr deleted the fix-btn-props-0625 branch June 26, 2025 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request (功能增强)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants